package com.zyh.day02.value

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object CoalesceTest {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
      .setAppName("mp")
      .setMaster("local[*]")
    val sc = new SparkContext(conf)
    val rdd1: RDD[Int] = sc.makeRDD(1 to 10,4)
    val rdd2: RDD[Int] = rdd1.coalesce(2)
    println("rdd1："+rdd1.getNumPartitions)
    println("rdd2："+rdd2.getNumPartitions)
    val rdd3: RDD[Int] = rdd2.mapPartitionsWithIndex((index, item) => {
      println(s"index = ${index}")
      item
    })





    rdd3.collect().foreach(println)







    sc.stop()
  }
}
